<?php

ini_set("display_errors", "On");//打开错误提示
ini_set("error_reporting",E_ALL);//显示所有错误

function p($data) {
    if(!$data or is_bool($data)) {
        var_dump($data);
    } else {
        echo '<pre>';
        print_r($data);
        echo '</pre>';
    }
}


include_once './WeightRandom.php';    // 改动前



$data = [
    1 => 1,
    2 => 1,
    500 => 500,
    501 => 500,
    502 => 500,
    503 => 500,
    1000 => 1000,
    1001 => 1000,
    1002 => 1000,
    1500 => 1500,
    1501 => 1500,
    1502 => 1500,
    1503 => 1500,
];
$res = [];

$count = 110000;
$obj = new WeightRandom();
$obj->load($data)->initAliases();
for ($i = 0; $i < $count; $i++) {
    $key = $obj->getRandom();

    if (empty($res[$key])) {
        $res[$key] = 1;
    } else {
        $res[$key]++;
    }
}

ksort($res);
echo '<pre>';
print_r($res);
echo '</pre>';